package com.itheima.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

//@Component
//@Aspect
/**
 * 主要做的事情：目标方法增强（before、after、around、AfterThrowing）
 * 目标方法怎么表述：Pointcut（execution、annotation）
 * execution：public * com.itheima.web.*.*(..)
 * https://www.cnblogs.com/liaojie970/p/7883687.html
 * execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)throws-pattern?)
 * */
public class MyAspect {

    @Pointcut("execution(public * com.itheima.web.*.*(..))")
    public void loginAspect(){
    }

    @Pointcut("@annotation(com.itheima.annotation.MyAnnotation)")
    public void annotationAspect(){
    }

    @Before("loginAspect()")
    public void doBefore(JoinPoint jp) throws Exception {
        System.out.println("before...");
    }

    @After("annotationAspect()")
    public void doAfter() {
        System.out.println("after...");
    }

    @AfterThrowing(value="loginAspect()",throwing="e")
    public void afterThrowing(JoinPoint joinPoint, Exception e){
        e.printStackTrace();
    }

}
